/*
	DS Kanji Flash
	Copyright (C) 2009,2010 Bernhard Schelling

	This file is part of DS Kanji Flash.

	DS Kanji Flash is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	DS Kanji Flash is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with DS Kanji Flash.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "global.h"
#include "dict.h"

static UL_IMAGE *imgKanji[4] = { NULL, NULL, NULL, NULL };
static int iPos[4] = {260, 370, 480, 590 };
static int iFrame;

class cSceneStart : public cScene
{
public:
	cSceneStart() : cScene(SCN_START)
		{ WantsEveryFrame = true; }

	virtual void Enter(void *p1, void *p2, void *p3)
	{
		ulSetLoadUtilitySource(VF_MEMORY);
		iFrame = 0;
	}

	virtual void ProcessInput()
	{
		if (!ul_keys.pressed.value) return;
		for (int i = 0; i < 4; i++)
			if (imgKanji[i]) ulDeleteImage(imgKanji[i]);
		cScene::GoTo(SCN_CARD);
	}
	
	virtual void DrawScreen_Top()
	{
		ulDrawGradientRect(0, 0, 256, 192, RGB15(25, 25, 25), RGB15(25, 25, 25), RGB15(31, 31, 31), RGB15(31, 31, 31));
		
		for (int i = 0; i < 4; i++)
		{
			iPos[i]-=2;
			if (iPos[i] <= -92) iPos[i] += 440;
			if ((iPos[i] >= 255) && (iPos[i] < 255+2))
			{
				int iKanji = rand()%kanjipool_num;
				if (imgKanji[i]) ulDeleteImage(imgKanji[i]);
				imgKanji[i] = ulLoadImageFilePNG((char*)kanjipool_png[iKanji], (int)(kanjipool_png[iKanji+1]-kanjipool_png[iKanji]), UL_IN_VRAM, UL_PF_PAL4);
				imgKanji[i]->stretchX = imgKanji[i]->stretchY = 96;
			}
			if (iPos[i] > 255) continue;
			ulDrawFillRect(iPos[i]-2, 44-2, iPos[i]+96+2, 44+96+2, COL_BLACK);
			ulDrawImageXY(imgKanji[i], iPos[i], 44);
		}

		displayString(ul_lcdFont, "Copyright (C) 2009,2010 Bernhard Schelling", 2, 150);
		displayString(ul_lcdFont, "DS Kanji Flash is distributed under the", 8, 170, RGB15(24, 24, 24));
		displayString(ul_lcdFont, "terms of the GNU General Public License", 8, 181, RGB15(24, 24, 24));

		ulScaleScreenView(inttof32(2), inttof32(2));
		displayString(fntJapanese, "DS KANJI FLASH", 12, 4, COL_YELLOW);
		ulScaleScreenView(inttof32(1), inttof32(1));

		iFrame++;
	}
	
	virtual void DrawScreen_Bottom()
	{
		ulDrawGradientRect(0, 0, 256, 192, RGB15(31, 31, 31), RGB15(31, 31, 31), RGB15(25, 25, 25), RGB15(25, 25, 25));

		char chrNum[14];
		sprintf(chrNum, "%d Kanjis", kanjipool_num);
		displayStringRight(ul_lcdFont, chrNum, 254, 2, RGB15(24, 24, 24));
		displayString(ul_lcdFont, VERSION_STRING, 2, 2, RGB15(24, 24, 24));

		displayStringCenter(ul_lcdFont, "GUIDE", 0, 12, 256, COL_YELLOW);

		ulDrawGradientRect(0, 31, 256, 161, RGB15(21, 21, 21), RGB15(21, 21, 21), RGB15(13, 13, 13), RGB15(13, 13, 13));
		bDrawFontShadows = false;
		displayString(ul_lcdFont, "  L-Button = Shows readings in hiragana", 8, 35);
		displayString(ul_lcdFont, "             Shows kanji meanings", 8, 46);
		displayString(ul_lcdFont, "  R-Button = Shows word translations", 8, 63);
		displayString(ul_lcdFont, "   Left/Up = Previous Kanji", 8, 80);
		displayString(ul_lcdFont, "X/Y-Button = Previous Kanji", 8, 97);
		displayString(ul_lcdFont, "Right/Down = Previous Kanji", 8, 114);
		displayString(ul_lcdFont, "A/B-Button = Previous Kanji", 8, 131);
		displayString(ul_lcdFont, "     Touch = Kanji Menu", 8, 149);
		bDrawFontShadows = true;

		if (iFrame % 20 < 16)
		{
			displayString(ul_lcdFont, "T O U C H   T O   S T A R T", 45, 172, COL_BLACK);
			displayString(ul_lcdFont, "T O U C H   T O   S T A R T", 47, 172, COL_BLACK);
			bDrawFontShadows = false;
			displayString(ul_lcdFont, "T O U C H   T O   S T A R T", 46, 172, COL_BLUE);
			bDrawFontShadows = true;
		}
	}

} SceneShowStart;
